package org.example.practiceexamples.repository;

import org.example.practiceexamples.dox.Appointment;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface AppointmentRepository extends CrudRepository<Appointment,String> {

    @Query("""
        select * from appointment;
    """)
    List<Appointment> findAllAppointments();

    @Query("""
        select * from appointment where lab_id =:lid and  week = :week and dayofweek =:day and section =:section 
    """)
    Appointment findAppointmentByLId(String lid, int week, int day, int section);

    @Query("""
        select * from appointment where appointment.lab_name =:labName and  week = :week and dayofweek =:day and section =:section 
    """)
    Appointment findAppointmentByLName(String labName, int week, int day, int section);

    @Query("""
        select * from appointment where id = :aid;
    """)
    Appointment findAppointmentById(String aid);

    @Modifying
    @Query("""
        delete from appointment where lab_name =:labName and  week = :week and dayofweek =:day and section =:section
    """)
    void deleteAppointmentByLName(String labName, int week, int day, int section);

    @Modifying
    @Query("""
        delete from appointment where lab_id =:lid and  week = :week and dayofweek =:day and section =:section
    """)
    void deleteAppointmentByLId(String lid, int week, int day, int section);

    @Modifying
    @Query("""
        delete from appointment where id = :id
    """)
    void deleteAppointmentById(String id);
}
